﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.Design.WebControls;
using System.Web.UI.Design;

namespace SPL.Web.UI
{
    /// <summary>
    /// A designer class for a strongly typed repeater <c>GppRepeater</c>
    /// </summary>
	public class GppRepeaterDesigner : System.Web.UI.Design.ControlDesigner
	{
	    /// <summary>
        /// Initializes a new instance of the <see cref="T:GppRepeaterDesigner"/> class.
        /// </summary>
		public GppRepeaterDesigner()
		{
		}

        /// <summary>
        /// Initializes the control designer and loads the specified component.
        /// </summary>
        /// <param name="component">The control being designed.</param>
		public override void Initialize(IComponent component)
		{
			if (!(component is GppRepeater))
			{ 
				throw new ArgumentException("Component is not a GppRepeater."); 
			} 
			base.Initialize(component); 
			base.SetViewFlags(ViewFlags.TemplateEditing, true); 
		}


		/// <summary>
		/// Generate HTML for the designer
		/// </summary>
		/// <returns>a string of design time HTML</returns>
		public override string GetDesignTimeHtml()
		{

			// Get the instance this designer applies to
			//
			GppRepeater z = (GppRepeater)Component;
			z.DataBind();

			return base.GetDesignTimeHtml();

			//return z.RenderAtDesignTime();

			//	ControlCollection c = z.Controls;
			//Totem z = (Totem) Component;
			//Totem z = (Totem) Component;
			//return ("<div style='border: 1px gray dotted; background-color: lightgray'><b>TagStat :</b> zae |  qsdds</div>");

		}
	}

    /// <summary>
    /// A strongly typed repeater control for the <c cref="GppRepeater"></c> Type.
    /// </summary>
	[Designer(typeof(GppRepeaterDesigner))]
	[ParseChildren(true)]
	[ToolboxData("<{0}:GppRepeater runat=\"server\"></{0}:GppRepeater>")]
	public class GppRepeater : Control, System.Web.UI.INamingContainer
	{
	    /// <summary>
        /// Initializes a new instance of the <see cref="T:GppRepeater"/> class.
        /// </summary>
		public GppRepeater()
		{
		}

		/// <summary>
        /// Gets a <see cref="T:System.Web.UI.ControlCollection"></see> object that represents the child controls for a specified server control in the UI hierarchy.
        /// </summary>
        /// <value></value>
        /// <returns>The collection of child controls for the specified server control.</returns>
		public override ControlCollection Controls
		{
			get
			{
				this.EnsureChildControls();
				return base.Controls;
			}
		}

		private ITemplate m_headerTemplate;
		/// <summary>
        /// Gets or sets the header template.
        /// </summary>
        /// <value>The header template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(GppItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate HeaderTemplate
		{
			get { return m_headerTemplate; }
			set { m_headerTemplate = value; }
		}

		private ITemplate m_itemTemplate;
		/// <summary>
        /// Gets or sets the item template.
        /// </summary>
        /// <value>The item template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(GppItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate ItemTemplate
		{
			get { return m_itemTemplate; }
			set { m_itemTemplate = value; }
		}
			

		private ITemplate m_altenateItemTemplate;
        /// <summary>
        /// Gets or sets the alternating item template.
        /// </summary>
        /// <value>The alternating item template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(GppItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate AlternatingItemTemplate
		{
			get { return m_altenateItemTemplate; }
			set { m_altenateItemTemplate = value; }
		}

		private ITemplate m_footerTemplate;
        /// <summary>
        /// Gets or sets the footer template.
        /// </summary>
        /// <value>The footer template.</value>
		[Browsable(false)]
		[TemplateContainer(typeof(GppItem))]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		public ITemplate FooterTemplate
		{
			get { return m_footerTemplate; }
			set { m_footerTemplate = value; }
		}

        /// <summary>
        /// Gets or sets the data source ID.
        /// </summary>
        /// <value>The data source ID.</value>
		[Category("Data")]
		public virtual string DataSourceID
		{
			get
			{
				if (ViewState["DataSourceID"] == null)
				{
					return string.Empty;
				}
				return (string)ViewState["DataSourceID"];
			}
			set
			{
				ViewState["DataSourceID"] = value;
			}
		}

		//[Category("Data")]
		//public virtual string DataMember
		//{
		//    get
		//    {
		//        if (ViewState["DataMember"] == null)
		//        {
		//            return string.Empty;
		//        }
		//        return (string)ViewState["DataMember"];
		//    }
		//    set
		//    {
		//        ViewState["DataMember"] = value;
		//    }
		//}

		//private ProductDataSourceView m_currentView;

		System.Collections.IEnumerable m_currentView;
        /// <summary>
        /// Connects to data source view.
        /// </summary>
        /// <returns>an IEnumerable of DataSourceView</returns>
		private System.Collections.IEnumerable ConnectToDataSourceView()
		{
			if (m_currentView == null)
			{
				SPL.Web.Data.GppDataSource datasource = null;
				//First look in the naming container
            Control ctl = this.NamingContainer.FindControl(DataSourceID);
            if (ctl == null)
            {
               //if not found, look at the page level
               ctl = this.Page.FindControl(DataSourceID);
               if (ctl == null)
               {
                  throw new System.Web.HttpException("Datasource does not exists");
               }
            }
				datasource = ctl as SPL.Web.Data.GppDataSource;
				if (datasource == null)
				{
					throw new System.Web.HttpException("Datasource must be data control");
				}
				
				System.Collections.IEnumerable dsv = datasource.GetEntityList(); //this.DataMember);
				if (dsv == null)
				{
					throw new System.Web.HttpException("View not found");
				}
				m_currentView = dsv;
			}
			return m_currentView;
		}

        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
		protected override void CreateChildControls()
		{
			if (ChildControlsCreated)
			{
				return;
			}
			Controls.Clear();

			System.Collections.IEnumerable datas = (System.Collections.IEnumerable)ConnectToDataSourceView();

			if (datas != null)
			{
				if (m_headerTemplate != null)
				{
					Control headerItem = new Control();
					m_headerTemplate.InstantiateIn(headerItem);
					Controls.Add(headerItem);
				}

				int pos = 0;
				foreach (object o in datas)
				{
					SPL.Entities.Gpp entity = o as SPL.Entities.Gpp;
					GppItem container = new GppItem(entity);

					if (m_itemTemplate != null && (pos % 2) == 0)
					{
						m_itemTemplate.InstantiateIn(container);
					}
					else
					{
						if (m_altenateItemTemplate != null)
						{
							m_altenateItemTemplate.InstantiateIn(container);
						}
						else if (m_itemTemplate != null)
						{
							m_itemTemplate.InstantiateIn(container);
						}
						else
						{
							// no template !!!
						}
					}
					Controls.Add(container);
					pos++;
				}

				if (m_footerTemplate != null)
				{
					Control footerItem = new Control();
					m_footerTemplate.InstantiateIn(footerItem);
					Controls.Add(footerItem);
				}
				ChildControlsCreated = true;
			}
		}

        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.PreRender"></see> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> object that contains the event data.</param>
		protected override void OnPreRender(EventArgs e)
		{
			base.DataBind();
		}

		#region Design time
        /// <summary>
        /// Renders at design time.
        /// </summary>
        /// <returns>a  string of the Designed HTML</returns>
		internal string RenderAtDesignTime()
		{			
			return "Designer currently not implemented"; 
		}

		#endregion
	}

    /// <summary>
    /// A wrapper type for the entity
    /// </summary>
	[System.ComponentModel.ToolboxItem(false)]
	public class GppItem : System.Web.UI.Control, System.Web.UI.INamingContainer
	{
		private SPL.Entities.Gpp _entity;

        /// <summary>
        /// Initializes a new instance of the <see cref="T:GppItem"/> class.
        /// </summary>
		public GppItem()
			: base()
		{ }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:GppItem"/> class.
        /// </summary>
		public GppItem(SPL.Entities.Gpp entity)
			: base()
		{
			_entity = entity;
		}
		
        /// <summary>
        /// Gets the Id
        /// </summary>
        /// <value>The Id.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int64 Id
		{
			get { return _entity.Id; }
		}
        /// <summary>
        /// Gets the I1InputDate
        /// </summary>
        /// <value>The I1InputDate.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime I1InputDate
		{
			get { return _entity.I1InputDate; }
		}
        /// <summary>
        /// Gets the I2KhiAm
        /// </summary>
        /// <value>The I2KhiAm.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I2KhiAm
		{
			get { return _entity.I2KhiAm; }
		}
        /// <summary>
        /// Gets the I3Cond
        /// </summary>
        /// <value>The I3Cond.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I3Cond
		{
			get { return _entity.I3Cond; }
		}
        /// <summary>
        /// Gets the I4pCcp
        /// </summary>
        /// <value>The I4pCcp.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I4pCcp
		{
			get { return _entity.I4pCcp; }
		}
        /// <summary>
        /// Gets the I6Pi0101
        /// </summary>
        /// <value>The I6Pi0101.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I6Pi0101
		{
			get { return _entity.I6Pi0101; }
		}
        /// <summary>
        /// Gets the I7Fiq0401
        /// </summary>
        /// <value>The I7Fiq0401.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I7Fiq0401
		{
			get { return _entity.I7Fiq0401; }
		}
        /// <summary>
        /// Gets the I8Fiq0301
        /// </summary>
        /// <value>The I8Fiq0301.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I8Fiq0301
		{
			get { return _entity.I8Fiq0301; }
		}
        /// <summary>
        /// Gets the I9Fiq0302
        /// </summary>
        /// <value>The I9Fiq0302.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I9Fiq0302
		{
			get { return _entity.I9Fiq0302; }
		}
        /// <summary>
        /// Gets the I10Fi102ByPass
        /// </summary>
        /// <value>The I10Fi102ByPass.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I10Fi102ByPass
		{
			get { return _entity.I10Fi102ByPass; }
		}
        /// <summary>
        /// Gets the I11Fiq26010h
        /// </summary>
        /// <value>The I11Fiq26010h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I11Fiq26010h
		{
			get { return _entity.I11Fiq26010h; }
		}
        /// <summary>
        /// Gets the I12Fiq260124h
        /// </summary>
        /// <value>The I12Fiq260124h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I12Fiq260124h
		{
			get { return _entity.I12Fiq260124h; }
		}
        /// <summary>
        /// Gets the I13Fiq2601Da
        /// </summary>
        /// <value>The I13Fiq2601Da.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I13Fiq2601Da
		{
			get { return _entity.I13Fiq2601Da; }
		}
        /// <summary>
        /// Gets the I14Fiq26020h
        /// </summary>
        /// <value>The I14Fiq26020h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I14Fiq26020h
		{
			get { return _entity.I14Fiq26020h; }
		}
        /// <summary>
        /// Gets the I15Fiq260224h
        /// </summary>
        /// <value>The I15Fiq260224h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I15Fiq260224h
		{
			get { return _entity.I15Fiq260224h; }
		}
        /// <summary>
        /// Gets the I16Fiq2602Da
        /// </summary>
        /// <value>The I16Fiq2602Da.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I16Fiq2602Da
		{
			get { return _entity.I16Fiq2602Da; }
		}
        /// <summary>
        /// Gets the I17Fiq26030h
        /// </summary>
        /// <value>The I17Fiq26030h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I17Fiq26030h
		{
			get { return _entity.I17Fiq26030h; }
		}
        /// <summary>
        /// Gets the I18Fiq260324h
        /// </summary>
        /// <value>The I18Fiq260324h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I18Fiq260324h
		{
			get { return _entity.I18Fiq260324h; }
		}
        /// <summary>
        /// Gets the I19Fiq2603Da
        /// </summary>
        /// <value>The I19Fiq2603Da.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I19Fiq2603Da
		{
			get { return _entity.I19Fiq2603Da; }
		}
        /// <summary>
        /// Gets the I20XeBon
        /// </summary>
        /// <value>The I20XeBon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I20XeBon
		{
			get { return _entity.I20XeBon; }
		}
        /// <summary>
        /// Gets the I21Fiq2402
        /// </summary>
        /// <value>The I21Fiq2402.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I21Fiq2402
		{
			get { return _entity.I21Fiq2402; }
		}
        /// <summary>
        /// Gets the I22Me240h
        /// </summary>
        /// <value>The I22Me240h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I22Me240h
		{
			get { return _entity.I22Me240h; }
		}
        /// <summary>
        /// Gets the I23Me2424h
        /// </summary>
        /// <value>The I23Me2424h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I23Me2424h
		{
			get { return _entity.I23Me2424h; }
		}
        /// <summary>
        /// Gets the I24TenMeCondBh
        /// </summary>
        /// <value>The I24TenMeCondBh.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I24TenMeCondBh
		{
			get { return _entity.I24TenMeCondBh; }
		}
        /// <summary>
        /// Gets the I25Me250h
        /// </summary>
        /// <value>The I25Me250h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I25Me250h
		{
			get { return _entity.I25Me250h; }
		}
        /// <summary>
        /// Gets the I26Me2524h
        /// </summary>
        /// <value>The I26Me2524h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I26Me2524h
		{
			get { return _entity.I26Me2524h; }
		}
        /// <summary>
        /// Gets the I27Me260h
        /// </summary>
        /// <value>The I27Me260h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I27Me260h
		{
			get { return _entity.I27Me260h; }
		}
        /// <summary>
        /// Gets the I28Me2624h
        /// </summary>
        /// <value>The I28Me2624h.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I28Me2624h
		{
			get { return _entity.I28Me2624h; }
		}
        /// <summary>
        /// Gets the I29KctvNhanLpg
        /// </summary>
        /// <value>The I29KctvNhanLpg.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I29KctvNhanLpg
		{
			get { return _entity.I29KctvNhanLpg; }
		}
        /// <summary>
        /// Gets the I30KctvNhanCond
        /// </summary>
        /// <value>The I30KctvNhanCond.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I30KctvNhanCond
		{
			get { return _entity.I30KctvNhanCond; }
		}
        /// <summary>
        /// Gets the I31ApSuat
        /// </summary>
        /// <value>The I31ApSuat.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I31ApSuat
		{
			get { return _entity.I31ApSuat; }
		}
        /// <summary>
        /// Gets the I32Me13a
        /// </summary>
        /// <value>The I32Me13a.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I32Me13a
		{
			get { return _entity.I32Me13a; }
		}
        /// <summary>
        /// Gets the I33Me13b
        /// </summary>
        /// <value>The I33Me13b.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I33Me13b
		{
			get { return _entity.I33Me13b; }
		}
        /// <summary>
        /// Gets the I34Fiq5801
        /// </summary>
        /// <value>The I34Fiq5801.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I34Fiq5801
		{
			get { return _entity.I34Fiq5801; }
		}
        /// <summary>
        /// Gets the I35v21aMucBon
        /// </summary>
        /// <value>The I35v21aMucBon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I35v21aMucBon
		{
			get { return _entity.I35v21aMucBon; }
		}
        /// <summary>
        /// Gets the I36v21bMucBon
        /// </summary>
        /// <value>The I36v21bMucBon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I36v21bMucBon
		{
			get { return _entity.I36v21bMucBon; }
		}
        /// <summary>
        /// Gets the I37v21cMucBon
        /// </summary>
        /// <value>The I37v21cMucBon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I37v21cMucBon
		{
			get { return _entity.I37v21cMucBon; }
		}
        /// <summary>
        /// Gets the I38Tk21MucBon
        /// </summary>
        /// <value>The I38Tk21MucBon.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Double I38Tk21MucBon
		{
			get { return _entity.I38Tk21MucBon; }
		}
        /// <summary>
        /// Gets the I109NoteBcn
        /// </summary>
        /// <value>The I109NoteBcn.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I109NoteBcn
		{
			get { return _entity.I109NoteBcn; }
		}
        /// <summary>
        /// Gets the I110NoteSplbh
        /// </summary>
        /// <value>The I110NoteSplbh.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I110NoteSplbh
		{
			get { return _entity.I110NoteSplbh; }
		}
        /// <summary>
        /// Gets the I111NoteMeCondBh
        /// </summary>
        /// <value>The I111NoteMeCondBh.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I111NoteMeCondBh
		{
			get { return _entity.I111NoteMeCondBh; }
		}
        /// <summary>
        /// Gets the I112NoteMeCondNcs
        /// </summary>
        /// <value>The I112NoteMeCondNcs.</value>
		[System.ComponentModel.Bindable(true)]
		public System.String I112NoteMeCondNcs
		{
			get { return _entity.I112NoteMeCondNcs; }
		}
        /// <summary>
        /// Gets the Status
        /// </summary>
        /// <value>The Status.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32 Status
		{
			get { return _entity.Status; }
		}
        /// <summary>
        /// Gets the InputUser
        /// </summary>
        /// <value>The InputUser.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int32 InputUser
		{
			get { return _entity.InputUser; }
		}
        /// <summary>
        /// Gets the Hid
        /// </summary>
        /// <value>The Hid.</value>
		[System.ComponentModel.Bindable(true)]
		public System.Int64? Hid
		{
			get { return _entity.Hid; }
		}
        /// <summary>
        /// Gets the CreatedDate
        /// </summary>
        /// <value>The CreatedDate.</value>
		[System.ComponentModel.Bindable(true)]
		public System.DateTime CreatedDate
		{
			get { return _entity.CreatedDate; }
		}

        /// <summary>
        /// Gets a <see cref="T:SPL.Entities.Gpp"></see> object
        /// </summary>
        /// <value></value>
        [System.ComponentModel.Bindable(true)]
        public SPL.Entities.Gpp Entity
        {
            get { return _entity; }
        }
	}
}
